import unittest,time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

# 显示等待
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class BaiDu(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://www.baidu.com/')
        self.driver.maximize_window()
    def tearDown(self):
        time.sleep(5)
        self.driver.quit()
    def test_search_01(self):

        search = self.driver.find_element(By.ID, 'kw')
        search.send_keys('uI-web端自动化测试')
        time.sleep(3)
        # 键盘回车事件
        search.send_keys(Keys.ENTER)
        time.sleep(2)
        # 鼠标右键
        ActionChains(self.driver).context_click(search).perform()
        time.sleep(2)
        # 鼠标双击
        ActionChains(self.driver).double_click(search).perform()
        time.sleep(2)

        # self.assertEqual(True, False)  # add assertion here
    def test_search_02(self):
        self.driver.implicitly_wait(5)
        search = self.driver.find_element(By.ID, 'kw')
        search.send_keys('uI-web端自动化测试')
        time.sleep(1)
        # 键盘回车事件
        search.send_keys(Keys.ENTER)
        time.sleep(2)
        # # 鼠标右键
        # ActionChains(self.driver).context_click(search).perform()
        # time.sleep(2)
        # 鼠标三击
        ActionChains(self.driver).double_click(search).click(search).perform()
        time.sleep(2)
        # 复制
        search.send_keys(Keys.CONTROL,'c')
        time.sleep(10)
        # 设置鼠标悬停
        set = self.driver.find_element(By.NAME,'tj_settingicon')
        print(set.is_enabled())
        ActionChains(self.driver).move_to_element(set).perform()
        time.sleep(3)
        # # 点击设置
        # self.driver.find_element(By.XPATH,'//*[@id="s-usersetting-top"]').click()
        # time.sleep(3)
        self.driver.find_element(By.LINK_TEXT,'高级搜索').click()
        time.sleep(4)
        q1=self.driver.find_element(By.NAME,'q1')
        q1.send_keys(Keys.CONTROL,'v')
        time.sleep(3)
        ActionChains(self.driver).double_click(q1).perform()
        time.sleep(3)
        q1.send_keys(Keys.CONTROL,'c')
        time.sleep(3)
        q1.send_keys(Keys.CONTROL,'x')
        time.sleep(3)
        self.driver.find_element(By.NAME,'q4').send_keys(Keys.CONTROL,'v')
        time.sleep(5)
        # 点击事件
        self.driver.find_element(By.XPATH,'//*[@id="adv-setting-gpc"]/div/div[1]/i[1]').click()
        time.sleep(3)
        self.driver.find_element(By.XPATH, '//*[@id="adv-setting-gpc"]/div/div[2]/div[2]/p[4]').click()
        time.sleep(3)
        self.driver.find_element(By.XPATH, '//*[@id="adv-setting-ft"]/div/div[1]/i[1]').click()
        time.sleep(3)
        self.driver.find_element(By.XPATH, '//*[@id="adv-setting-ft"]/div/div[2]/div[2]/p[5]').click()
        time.sleep(5)
        self.driver.find_element(By.CSS_SELECTOR,'#adv-setting-8 > input.advanced-search-btn.c-btn.c-btn-primary.switch-button').click()
        time.sleep(5)
        # self.assertEqual(True, False)  # add assertion here


if __name__ == '__main__':
    unittest.main()